package com.deryun.tyl.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.deryun.tyl.bean.Policy;
import com.deryun.tyl.service.impl.PolicyServiceImpl;

@Controller
@RequestMapping("policy")
public class PolicyController {

	@Resource(name="policyServiceImpl")
	private PolicyServiceImpl policyServiceImpl;
	
	@RequestMapping("/addPolicy")
	public String addPolicy(HttpServletRequest request,Policy policy){
		int result = policyServiceImpl.addPolicy(request,policy);
		return "redirect:/ftoac/loadZcfg";
	}
	
	/***
	 * 获取所有政策法规
	 * @return
	 */
	@RequestMapping("/getAllPolicy")
	public List<Policy> getAllPolicy(){
		return policyServiceImpl.getAllPolicy();
	}
	
	/***
	 * 删除制定政策法规
	 * @param id
	 * @return
	 */
	@RequestMapping("/deletePolicy")
	public String deletePolicy(int id)
	{		
		policyServiceImpl.deletePolicy(id);
		return "redirect:/ftoac/loadZcfg";
	}
	
	@RequestMapping("/getNewPolicys")
	public String getNewPolicys(){
		return "success";
	}
	
	@RequestMapping("/modifyPolicy")
	public String modifyPolicy(Policy policy){
		policyServiceImpl.modifyPolicy(policy);
		return "redirect:/ftoac/loadZcfg";
	}
	
	@RequestMapping("/getPolicyById")
	public String getPolicyById(HttpServletRequest request,int id){
		Policy message = policyServiceImpl.getPolicyById(id);
		request.setAttribute("message", message);
		return "success";
	}
	
	@RequestMapping("/setResult")
	public String setResult(Policy policy){
		policyServiceImpl.setResult(policy);
		return "redirect:/ftoac/loadZcfg";
	}
}
